package io.renren.modules.diycake.service.impl;

import io.renren.modules.diycake.utils.MD5;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.diycake.dao.UserAccountDao;
import io.renren.modules.diycake.entity.UserAccountEntity;
import io.renren.modules.diycake.service.UserAccountService;
import org.springframework.util.StringUtils;


@Service("userAccountService")
public class UserAccountServiceImpl extends ServiceImpl<UserAccountDao, UserAccountEntity> implements UserAccountService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<UserAccountEntity> page = this.page(
                new Query<UserAccountEntity>().getPage(params),
                new QueryWrapper<UserAccountEntity>()
        );

        return new PageUtils(page);
    }


    @Override
    public boolean updatePassword(Integer id, String oldPassword, String newPassword) {

        UserAccountEntity userAccount = baseMapper.selectById(id);

        UserAccountEntity account = new UserAccountEntity();
        account.setId(id);
        account.setPassword(MD5.encrypt(newPassword));
        baseMapper.updateById(account);
        return true;
    }

}